/**
 * @author helio
 */
if (!SALE.setting) SALE.setting = {}

if (!SALE.setting.LoginPopupPanel) {
	SALE.setting.LoginPopupPanel = Ext.extend(SALE.basicGridPanel, {
	
		layout: 'fit',
		border: false,
		bodyStyle : 'background-color: transparent;', 
		initComponent: function(){
			
			this.inputForm = new Ext.FormPanel({
				labelWidth: 60,
				border: false,
				autoHeight: true,
				buttonAlign: 'center',
				defaultType: 'textfield',
				bodyStyle : 'background-color: transparent;', 
												
				items: [{
					fieldLabel: '用户名',
                    name: 'loginid',
                    anchor: '95%'
                }, {
                	fieldLabel: '密码',
                    inputType: 'password',
                    name: 'password',
					style:'margin-top:8px',
                    anchor: '95%'
                }],
		      
                keys:{
					key: Ext.EventObject.ENTER,
					fn: this.onSave.createDelegate(this)
				},
				buttons: [{
                    text: '登录',
					id:'loginBtn',
					iconCls: 'btn-login',					
            		scale: 'medium',
                    listeners: {
		        		"click": this.onSave.createDelegate(this)
                    }
                }]
			});
			
			this.items = this.inputForm;
			
			SALE.setting.LoginPopupPanel.superclass.initComponent.call(this);
		},
						
		onSave : function() {
			if(this.inputForm.form.isValid()) {
				Ext.MessageBox.show({
					msg: '正在验证用户信息，请等待...',
			        progressText: 'Saving...',
			        width:300,
			        wait:true,
			        waitConfig: {interval:200},
			        icon:'ext-mb-download', //custom class in msg-box.html
			        animEl: 'loginBtn'
			    });
				
				setTimeout(function(){
					SALE.Action.loginAction(this.loginSuccessHandler.createDelegate(this),this.inputForm.form);
    			}.createDelegate(this), 200);
			}
		},
		
		loginSuccessHandler : function() {
			this.close();
		}
	});
	
	Ext.reg('loginpopup', SALE.setting.LoginPopupPanel);
}

function showLoginPopupWindow() {
	this.inputWin = new Ext.Window({
 		
	 	title: '登录系统',
		closable: false,
		frame: true,
		modal: true,
		width: 400,
		height: 260,
		layout: 'border',
		closeAction :'close',
		bodyStyle: "padding:10px;",	
		items: [{
			region: 'north',
			border: false,
			bodyStyle : 'background-color: transparent;', 
			height: 60,
            html: '<div style="text-align:center;"><h1 style="float:inherit;">用户登录</h1><hr/>	</div>'
		}, {
			region: 'center',
			margins: '20 20 20 20',
			xtype : "loginpopup"
		}]
	});
	
	this.inputWin.show();
}